package com.example.demo.controller;

import com.example.demo.annotation.Api;
import com.example.demo.domain.PageResult;
import com.example.demo.domain.exam.ExamClass;
import com.example.demo.domain.exam.QueryModel;
import com.example.demo.domain.exam.condition.ExamClassCondition;
import com.example.demo.domain.exam.condition.ExamClassStaffCondition;
import com.example.demo.domain.exam.condition.ExamStaffCondition;
import com.example.demo.dto.ExamClassRelationDTO;
import com.example.demo.dto.ExamClassStaffDTO;
import com.example.demo.dto.TrainingClassDTO;
import com.example.demo.service.exam.ExamClassService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 考试班级
 * @author HP
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/exam/class")
public class ExamClassController {

    private final ExamClassService examClassService;

    /**
     * 创建考试班级
     */
    @Api
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public void createExamClass(@RequestBody ExamClass entity) {
        examClassService.createExamClass(entity);
    }

    /**
     * 查询考试班级分页接口
     * @param model 查询条件等
     * @return 分页结果
     */
    @Api
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    public PageResult<ExamClass> page(@RequestBody QueryModel<ExamClassCondition> model) {
        return examClassService.page(model);
    }

    /**
     * 更新班级
     * @param entity 班级实体
     */
    @Api
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public void updateExamClass(@RequestBody ExamClass entity) {
        examClassService.updateExamClass(entity);
    }


    /**
     * 为考试班级添加人员
     * @param dto 考试班级实体
     */
    @Api
    @RequestMapping(value = "/staff/add", method = RequestMethod.POST)
    public void addStaff(@RequestBody ExamClassRelationDTO dto) {
        examClassService.addStaffForExamClass(dto);
    }

    /**
     * 为考试班级删除人员
     * @param dto 考试班级实体
     */
    @Api
    @RequestMapping(value = "/staff/delete", method = RequestMethod.POST)
    public void deleteStaff(@RequestBody ExamClassRelationDTO dto) {
        examClassService.deleteStaffForExamClass(dto);
    }


    /**
     * 获取培训班信息
     * @return 培训班实体
     */
    @Api
    @RequestMapping(value = "/get/training-class", method = RequestMethod.GET)
    List<TrainingClassDTO> getTrainingClass() {
        return examClassService.getTrainingClass();
    }

    /**
     * 获取培训班人员
     * @param classId 班级标识
     * @return 人员实体
     */
    @Api
    @RequestMapping(value = "/staff/get", method = RequestMethod.GET)
    List<ExamClassStaffDTO> getStaff(@RequestParam Long classId) {
        return examClassService.getStaff(classId);
    }

    /**
     * 获取培训班人员分页接口
     * @param model 条件：注意与不分页有区别 id为培训班id，classId为考试班级；id与classId比传，username可传可不传，用户需要按名称模糊查询时才使用
     * @return 人员实体
     */
    @Api
    @RequestMapping(value = "/staff/get", method = RequestMethod.POST)
    List<ExamClassStaffDTO> pageStaff(@RequestBody QueryModel<ExamStaffCondition> model) {
        return examClassService.pageStaff(model);
    }

    /**
     * 获取班级信息
     * @param classId 班级Id
     * @return 班级详细信息
     */
    @Api
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public ExamClass getByClassId(@RequestParam Long classId) {
        return examClassService.getByClassId(classId);
    }

    /**
     * 班级人员信息
     * @param model 班级标识必传
     * @return 班级人员信息
     */
    @Api
    @RequestMapping(value = "/staff/page", method = RequestMethod.POST)
    public PageResult<ExamClassStaffDTO> pageExamClassStaff(@RequestBody QueryModel<ExamClassStaffCondition> model) {
        return examClassService.pageExamClassStaff(model);
    }

}
